package com.sky.handler;

import com.sky.entity.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @projectName: netty-cloud
 * @package: com.sky.handler
 * @className: MyUserDetails
 * @author: zhl
 * @description: TODO
 * @date: 2024/4/28 14:56
 * @version: 1.0
 */
public class MyUserDetails implements UserDetails {
    private String userName;

    private String password;

    private Collection<? extends GrantedAuthority> authorities;

    private static final long serialVersionUID = 1L;

    public MyUserDetails(SysUser sysUser,Collection<? extends GrantedAuthority> authorities) {
        this.userName = sysUser.getUserName();
        this.password = sysUser.getPassword();
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }


    @Override
    public String toString() {
        return this.userName;
    }

    @Override
    public int hashCode() {
        return userName.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return this.toString().equals(obj.toString());
    }
}
